***********************************************************
*** TABLE A2
***********************************************************
use "${path}data_table.dta", clear

gen groub_nblabex=1
replace groub_nblabex=2 if nb_labex_corrected>1 &  nb_labex_corrected!=.
gen groub_nblabex2=1 if nb_labex_corrected==1
replace groub_nblabex2=2 if nb_labex_corrected==2 | nb_labex_corrected==3

bysort id_2019 year: gen id_yr=_n
keep if id_yr==1
keep if year<2010
global bal_var "age npubs   citations_new np_if_3y mean_aut   nbpub_same_labex nb_collab_same_labex nb_collabpub_same_labex  npubs_outside nb_first_same_labex "
foreach var in $bal_var{
bysort id_2019: egen m_`var'=mean(`var')		
} 
global bal_var2 " m_npubs  m_citations_new m_np_if_3y m_mean_aut   m_nbpub_same_labex m_nb_collab_same_labex  m_nb_collabpub_same_labex  m_npubs_outside m_nb_first_same_labex " 
*biologie_f   chimie_f physique_tot_f sciences_ingenieur_f mathematiques_f SHS_f"
label var m_npubs "Number of articles (\emph{Pubs})"
label var  m_nbpub_same_labex "Number of collaborative articles within the cluster (\emph{CollaPubs})"
label var  m_nb_collab_same_labex "Number of links within the cluster (\emph{Links})"
label var  m_nb_collabpub_same_labex "Number of collaborations within the cluster (\emph{Collaborations})"
label var  m_npubs_outside "Number of external articles  (\emph{ExternalPubs})"
label var  m_nb_first_same_labex   "Number of new links within the cluster (\emph{NewLinks})"
label var  m_citations_new "Number of articles weighted by cites  (\emph{Cites})"
label var  m_np_if_3y "Number of articles weighted by the journal impact factor (\emph{AIF})"
label var m_age "Age (\emph{Age})"
label var m_mean_aut "Mean number of authors  (\emph{TeamSize})"
keep if year==2009 
est clear
local tabnom  "descriptives_one_vs_more"
eststo all: quietly estpost summarize  $bal_var2     
eststo domestic: quietly estpost summarize $bal_var2   if groub_nblabex == 1  
eststo foreign: quietly estpost summarize $bal_var2     if groub_nblabex==2
eststo diff: quietly estpost ttest $bal_var2   , by(groub_nblabex) unequal
esttab  domestic foreign  diff  , ///
mtitles("1 cluster" "More clusters "  "Difference t-test") ///
cells("mean(pattern(1 1 0 ) fmt(2)) sd(pattern(1 1 0)) b(pattern(0 0 1 ) fmt(2)) p(pattern(0 0 1 ) par fmt(2))") label
esttab  domestic foreign  diff  using `tabnom'.tex, replace  ///
mtitles("1 cluster" "More clusters "  "Difference t-test") ///
cells("mean(pattern(1 1 0 ) fmt(2)) sd(pattern(1 1 0)) b(pattern(0 0 1 ) fmt(2)) p(pattern(0 0 1 ) par fmt(2))") label
est clear

local tabnom  "descriptives_one_vs_two_three"
eststo : quietly estpost summarize $bal_var2     
eststo domestic1: quietly estpost summarize $bal_var2 if groub_nblabex2 == 1  
eststo foreign1: quietly estpost summarize $bal_var2 if groub_nblabex2==2 
eststo diff1: quietly estpost ttest $bal_var2 , by(groub_nblabex2) unequal
esttab  domestic1 foreign1 diff1, ///
mtitles("1 cluster" "2 or 3 clusters"  "Difference t-test") ///
cells("mean(pattern(1 1 0 ) fmt(2)) sd(pattern(1 1 0)) b(pattern(0 0 1 ) fmt(2)) p(pattern(0 0 1 ) par fmt(2))") label
esttab  domestic1 foreign1  diff1  using `tabnom'.tex, replace  ///
mtitles("1 cluster" "2 or 3 clusters"  "Difference t-test") ///
cells("mean(pattern(1 1 0 ) fmt(2)) sd(pattern(1 1 0)) b(pattern(0 0 1 ) fmt(2)) p(pattern(0 0 1 ) par fmt(2))") label
